import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Test {

	public static void main(String[] args) {
		try {
			//第一步: 加载驱动程序
		Class.forName("com.mysql.jdbc.Driver");
			//连接数据库,不要忘了设置编码格式为 utf-8
		String url = "jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=utf8";
			//用户名root
		String user = "root";
			//数据库密码:123456
		String pass = "123456";
			//连接数据库
		Connection con = DriverManager.getConnection(url, user, pass);
		Statement st = con.createStatement();
		ResultSet rs = st.executeQuery("select * from student1");
		while(rs.next()) {
			System.out.println("学号:"+rs.getString("sno")+
					         ",院系:"+rs.getString("sdep")+
					         ",性别:"+rs.getString("ssex")+
					         ",年龄:"+rs.getString("sage")+
					         ",姓名:"+rs.getString("sname"));
			}
			rs.close();
			st.close();
			con.close();
		} catch (ClassNotFoundException e) {
			
			e.printStackTrace();
		} catch (SQLException e) {
			
			e.printStackTrace();
		}

	}

}
